package estore;

import java.util.HashSet;
import java.util.Set;

public class Product3 implements Comparable<Product3> {
    private String id;
    private String name;
    private double price;
    private int stock;
    private Set<String> tags;

    // 无标签的构造函数
    public Product3(String id, String name, double price, int stock) {
        this(id, name, price, stock, new HashSet<>());
    }

    // 带标签的构造函数
    public Product3(String id, String name, double price, int stock, Set<String> tags) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.tags = (tags != null) ? tags : new HashSet<>();
    }

    // Getter 方法
    public String getId() { return id; }
    public String getName() { return name; }
    public double getPrice() { return price; }
    public int getStock() { return stock; }
    public Set<String> getTags() { return tags; }

    // Setter 方法
    public void setTags(Set<String> tags) {
        this.tags = (tags != null) ? tags : new HashSet<>();
    }

    @Override
    public int compareTo(Product3 other) {
        return this.id.compareTo(other.id);
    }

    @Override
    public String toString() {
        String baseInfo = String.format("商品ID: %s | 名称: %-15s | 价格: ¥%-8.2f | 库存: %d",
                id, name, price, stock);

        if (tags != null && !tags.isEmpty()) {
            return baseInfo + " | 标签: " + tags;
        } else {
            return baseInfo;
        }
    }
}